import {getTrashes,restoreTrash,delTrash,emptyTrash} from '../../utils/nc/trash'
import {description, path, query, request, summary, tagsAll} from "koa-swagger-decorator-fork";
import responseMapper from "../../utils/responseMapper";

@tagsAll(['TrashFile'])
export default class TrashFileRouter {
    @request('GET', '/trashes')
    @summary('find trashes')
    @description('查询回收站文件列表')
    @query({
        path:{type:'string'},
        pattern:{type:'string',example:'lnkg'}
    })
    static async findTrashes(ctx) {
        let path = ctx.query.path||'/',pattern = ctx.query.pattern?.split(','),treeMode = ctx.query.treeMode=='true'?true:false
        let files = await getTrashes(ctx.client,ctx.user,path,pattern)
        let result = responseMapper.wrapResponse(ctx,files,path,treeMode)
        ctx.body = result
    }

    @request('PUT', '/trashes/{name}')
    @summary('restore trash by name')
    @description('从回收站恢复')
    @path({ name: { type: 'string', required: true } })
    static async restoreTrash(ctx) {
        await restoreTrash(ctx.client,ctx.user,ctx.params.name)
        ctx.body = {}
    }


    @request('DELETE', '/trashes/{name}')
    @summary('delete trash by name')
    @description('从回收站删除')
    @path({ name: { type: 'string', required: true } })
    static async delTrash(ctx) {
        await delTrash(ctx.client,ctx.user,ctx.params.name)
        ctx.body = {}
    }

    @request('DELETE', '/trashes')
    @summary('empty trash')
    @description('清空回收站')
    static async emptyTrash(ctx) {
        await emptyTrash(ctx.client,ctx.user)
        ctx.body = {}
    }
}
